{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ca7dc73c-a305-41a9-954f-18e0ba50ca1c",
   "metadata": {},
   "source": [
    "Chapter 07\n",
    "# 使用NumPy计算矩阵乘法\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "76908e5c-40a8-471c-8a4a-88044e58c592",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "# 定义矩阵 A 和 B\n",
    "A = np.array([[1, 2, 10, 20],\n",
    "              [3, 4, 30, 40]])\n",
    "        \n",
    "B = np.array([[1, 3],\n",
    "              [2, 4],\n",
    "              [10, 30],\n",
    "              [20, 40]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "fd25d5cf-9e69-4559-bac1-7213169404c2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 505 1111]\n",
      " [1111 2525]]\n"
     ]
    }
   ],
   "source": [
    "C = A @ B; print(C)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "48bbe308-06cb-4b2b-ba8f-91bde286292f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[  10   14  100  140]\n",
      " [  14   20  140  200]\n",
      " [ 100  140 1000 1400]\n",
      " [ 140  200 1400 2000]]\n"
     ]
    }
   ],
   "source": [
    "D = B @ A; print(D)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
